readline-utils
Readline utils, for moving the cursor, clearing lines, creating a readline interface, and more.
Install
Install with npm:
$ npm install --save readline-utils
Usage
var utils = require('readline-utils');
API
Create a readline interface with the given options
.
Params
Move cursor up by n
lines.
Params
rl
{Readline}: Readline interfacen
{Number}: Lines up to move. Default is 1
.
Move cursor down by n
lines.
Params
rl
{Readline}: Readline interfacen
{Number}: Lines down to move. Default is 1
.
Move cursor left by n
colums.
Params
rl
{Readline}: Readline interfacen
{Number}: Characters to move left. Default is 1
.
Move cursor right by n
colums.
Params
rl
{Readline}: Readline interfacen
{Number}: Characters to move right. Default is 1
.
Move cursor up, down, left or right by 1
line.
Params
rl
{Readline}: Readline interface
Example
var utils = require('readline-utils');
var rl = utils.createInterface();
rl.input.on('keypress', function(str, key) {
utils.move(rl, key);
});
Callback function for the keypress
event, to automatically move cursor up, down, left or right by 1
line.
Params
rl
{Readline}: Readline interface
Example
var utils = require('readline-utils');
var rl = utils.createInterface();
rl.input.on('keypress', utils.auto(rl));
Clear n
lines after the cursor.
Params
rl
{Readline}: Readline interfacen
{Number}: Number of lines to clear
Clear the terminal.
Params
rl
{Readline}: Readline interfacen
{Number}: Number of lines to clear
Get the last line from the given str
Params
str
{String}returns
{String}
Get the height (rows) of the given str
Params
str
{String}returns
{Number}
Hide the cursor.
Params
rl
{Readline}: Readline interfacereturns
{Object}: readline-utils object for chaining
Show the cursor.
Params
rl
{Readline}: Readline interfacereturns
{Object}: readline-utils object for chaining
Close the interface, remove event listeners, and restore/unmute prompt functionality
Params
rl
{Readline}: Readline interfacereturns
{Object}: readline-utils object for chaining
Close the interface when the keypress is ^C
Params
rl
{Readline}: Readline interfacereturns
{Object}: readline-utils object for chaining
Normalize values from keypress events.
Params
str
{String}: Keypress source string emitted by the keypress
event.key
{Object}: Keypress key
object emitted by the keypress
event.returns
{Object}: Normalized event
object
Erase n
lines
Params
n
{Number}returns
{String}: Returns the unicode to erase lines
Example
utils.eraseLines(3);
Remove lines from the bottom of the terminal.
Params
rl
{Number}: Readline interfacelines
{Number}: Number of lines to removeheight
{Number}: Content heightreturns
{Object}: Returns the readline-utils object for chaining
Remember the cursor position
returns
{Object}: readline-utils object
Restore the cursor position to where it has been previously stored.
returns
{Object}: readline-utils object
Get the width of the terminal
Params
rl
{Readline}: Readline interfacereturns
{Number}: Returns the number of columns.
Break lines longer than the cli width so we can normalize the
natural line returns behavior accross terminals. (I don't see how
this can work consistently. It seems brittle and will probably be replaced
with https://github.com/jonschlinkert/word-wrap)
Params
lines
{Array}: Array of lineswidth
{Number}: Terminal width
Joins the lines returned from .breakLines.
Params
lines
{Array|String}: String or array of lines.width
{Number}: Terminal widthreturns
{String}
Ensure the given str
ends in a newline.
Params
str
{String}: The input stringreturns
{String}
Example
console.log(utils.normalizeLF('foo'));
Attribution
Some of this code was borrowed from [Inquirer][].
About
Related projects
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guide for advice on opening issues, pull requests, and coding standards.
Contributors
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb
Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Author
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert.
Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on May 05, 2017.